package com.google.code.timeeditapplication.model.implementation;

import java.util.ArrayList;
import java.util.List;

/**
 * Describes a Schedule, contains a List of ScheduleItems, and a Name
 * 
 * @author deas
 * 
 */
public class Schedule {
	private final ArrayList<ScheduleItem> schedule;
	private String name;
	private final String metaData;

	/**
	 * 
	 * @param schedule
	 *            List of ScheduleItems to be on the Schedule
	 * @param name
	 *            Name of the Schedule
	 * @param metaData
	 *            Meta data of icalendar file (version, calscale etc...),
	 *            optional
	 */
	public Schedule(final List<ScheduleItem> schedule, final String name,
			final String metaData) {
		this.name = name;
		this.metaData = metaData;
		this.schedule = new ArrayList<ScheduleItem>();
		for (final ScheduleItem sI : schedule) {
			this.schedule.add(new ScheduleItem(sI));
		}
	}

	/**
	 * 
	 * @param s
	 *            Schedule to be cloned
	 */
	public Schedule(final Schedule s) {
		this.name = s.name;
		this.metaData = s.metaData;
		this.schedule = new ArrayList<ScheduleItem>();
		for (final ScheduleItem sI : s.schedule) {
			this.schedule.add(sI);
		}
	}

	/**
	 * 
	 * @return MetaData of schedule
	 */

	public String getMetaData() {
		return this.metaData;
	}

	/**
	 * 
	 * @return a list of all ScheduleItems in Schedule
	 */
	public ArrayList<ScheduleItem> getItems() {
		final ArrayList<ScheduleItem> tempList = new ArrayList<ScheduleItem>();
		for (final ScheduleItem sI : this.schedule) {
			tempList.add(new ScheduleItem(sI));
		}
		return tempList;
	}

	/**
	 * 
	 * @return Name of Schedule
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * 
	 * @param sI
	 *            ScheduleItem to add to the Schedule
	 */
	public void addItem(final ScheduleItem sI) {
		this.schedule.add(sI);
	}

	/**
	 * 
	 * @param sIList
	 *            List of ScheduleItems to add to the Schedule
	 */
	public void addItems(final List<ScheduleItem> sIList) {
		for (final ScheduleItem sI : sIList) {
			this.schedule.add(sI);
		}
	}

	/**
	 * 
	 * @param name
	 *            new name for Schedule
	 */
	public void setName(final String name) {
		this.name = name;
	}
}
